package com.dyc.maitaole.controller;

import com.dyc.maitaole.entity.Category;
import com.dyc.maitaole.service.CategoryService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.servlet.ModelAndView;

import java.util.List;

@Controller
@RequestMapping("/category")
public class CategoryController {
    @Autowired
    private CategoryService categoryService;

    @RequestMapping("/categorylist")
    public ModelAndView findAll() {

        List<Category> categories = categoryService.findAllCategories();
        ModelAndView modelAndView = new ModelAndView("/index.jsp");
        modelAndView.addObject("categories", categories);
        return modelAndView;

    }
}
